//
//  LYSelectDownLoadView.m
//  LYouSubscribeApp
//
//  Created by grx on 2018/12/17.
//  Copyright © 2018年 grx. All rights reserved.
//

#import "LYSelectDownLoadView.h"

@implementation LYSelectDownLoadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self crratUI];
    }
    return self;
}

-(void)crratUI{
    /** 选择下载清晰度 */
    UILabel *titlelable = [UILabel new];
    titlelable.textColor = [UIColor lightGrayColor];
    titlelable.text = @"选择下载清晰度";
    titlelable.font = LYFont_Medium(14);
    [self addSubview:titlelable];
    [titlelable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.centerX.equalTo(self);
        make.height.mas_equalTo(30);
    }];
    /** 关闭按钮 */
    UIButton *closeBtn = [UIButton new];
    [closeBtn setBackgroundImage:[UIImage imageNamed:@"guanbi-2"] forState:UIControlStateNormal];
    [self addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-15);
        make.centerX.equalTo(self);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    [closeBtn addTarget:self action:@selector(closeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    /** 选择清晰度 */
    NSArray *titleArray = @[@"低清",@"高清"];
    for (int i=0; i<2; i++) {
        UIButton *selectBtn = [UIButton new];
        [self addSubview:selectBtn];
        [selectBtn setTitle:titleArray[i] forState:UIControlStateNormal];
        selectBtn.titleLabel.font = LYFont_Medium(14);
        [selectBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        selectBtn.tag = i+10;
        [selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titlelable).offset(40);
            make.left.equalTo(self).offset(i*SCREEN_WIDTH/2);
            make.width.mas_equalTo(SCREEN_WIDTH/2);
            make.height.mas_equalTo(40);
        }];
        if (selectBtn.tag==11) {
            [selectBtn setImage:[UIImage imageNamed:@"gaoqing"] forState:UIControlStateNormal];
            [selectBtn setImageEdgeInsets:UIEdgeInsetsMake(-1,-14,0,0)];
        }
        [selectBtn addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(controlViewDidClick:)];
    [self addGestureRecognizer:tap];
}

#pragma mark - 下载
- (void)controlViewDidClick:(id)sender {
    if (self.downLoadBlock) {
        self.downLoadBlock(10);
    }
}

-(void)selectBtnClick:(UIButton *)sender{
    if (self.downLoadBlock) {
        self.downLoadBlock(sender.tag);
    }
}

-(void)closeBtnClick:(UIButton *)sender{
    if (self.closeBlock) {
        self.closeBlock();
    }
}

@end
